package Thread;

class MyThread implements Runnable{
    private int num;
    private int tmp;

    public MyThread(){}
    public MyThread(int num){
        this.num = num;
        this.tmp = 1;
    }

    public synchronized void saleTicket(){
        if(num<=0){
            return;
        }
        System.out.println(Thread.currentThread().getName()+tmp);
        tmp++;
        num--;
    }

    @Override
    public void run() {
        while (num>0){
            saleTicket();
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}




public class Test01_Thread {
    public static void main(String[] args) {
        MyThread t = new MyThread(10);
        new Thread(t,"窗口1：").start();
        new Thread(t,"窗口2：").start();
        new Thread(t,"窗口3：").start();
    }
}
